#!/usr/bin/python

import shutil
import os
f_ip = input("please input ipaddr:")
f_mask = input("please input mask:")
f_gateway = input("please input gateway:")
f_dns = input("please input dns1:")

shutil.copy("/etc/sysconfig/network-scripts/ifcfg-ens33","/etc/sysconfig/network-scripts/ifcfg-ens33.bak")
f = open("/etc/sysconfig/network-scripts/ifcfg-ens33","w")
f.write("DEVICE=ens33\nONBOOT=yes\nBOOTPROTO=none\nIPADDR=%s" % f_ip)
f.write("\nNETMASK=%s" % f_mask)
f.write("\nGATEWAY=%s" % f_gateway)
f.write("\nDNS1=%s\n" % f_dns)
f.close()
os.system("service network restart")
if os.system("ping -c2 -w0.1 www.baidu.com") != 0:
    os.rename("/etc/sysconfig/network-scripts/ifcfg-ens33.bak", "/etc/sysconfig/network-scripts/ifcfg-ens33")